/**
 * Created by Elsa on 2017/9/14.
 */

layui.define([ 'layer','jquery'], function(exports){
    var $ = layui.jquery,
        layer = layui.layer;

    $("body").keydown(function() {
        if (event.keyCode == "13") {//keyCode=13是回车键
            $('#LoginBtn').click();
        };
    });

    $('#LoginBtn').on('click',function () {
        if($("#UserName").val() == ''){
            layer.msg('请输入手机号!');
        }
        else if($("#Password").val() == ''){
            layer.msg('请输入密码!');
        }
        else if($("#VrifyCode").val() == ''){
            layer.msg('请输入验证码!');
        }
        else {
            $.ajax({
                url: contextPath+"/loginUser",
                type: "POST",
                data:{'username':$("#UserName").val(),'password':$("#Password").val(),'vrifycode':$("#VrifyCode").val()},
                xhrFields:{withCredentials:true},
                success: function(data) {
                    if(data.message == "登录成功"){
                        // $.cookie('JSESSIONID',data.token,{expire:7, path:'/'});
                        window.location.href='index.html';
                    }else{
                        layer.msg(data.message);
                        $('#defaultKaptcha').click();
                    }
                }
            });
        }
    });
    $('#varCode').attr('src',contextPath+'/defaultKaptcha?d='+new Date()*1);  
    $('#varCode').on('click',function () {
        this.src=contextPath+'/defaultKaptcha?d='+new Date()*1
    });
    $(function(){
        $(".cover-wrapper").css("opacity","1");
        $(".cover-wrapper").css("-webkit-transform","scale(1) translateY(-50%)");
        $(".cover-wrapper").css("-moz-transform","scale(1) translateY(-50%)");
        $(".cover-wrapper").css("-ms-transform","scale(1) translateY(-50%)");
        $(".cover-wrapper").css("transform","scale(1) translateY(-50%)");
    });
    exports('login', {}); //注意，这里是模块输出的核心，模块名必须和use时的模块名一致
});
